#include <stdio.h>
#include <stdlib.h>

typedef int ElementType;
typedef struct Node *PtrToNode;
struct Node {
    ElementType Data;
    PtrToNode   Next;
};
typedef PtrToNode List;

List Read(); /* 细节在此不表 */
void Print( List L ); /* 细节在此不表；空链表将输出NULL */

List Merge( List L1, List L2 );

int main()
{
    List L1, L2, L;
    L1 = Read();
    L2 = Read();
    L = Merge(L1, L2);
    Print(L);
    Print(L1);
    Print(L2);
    return 0;
}
List Read()
{
    List head,tail,p;
    int i,n;
    scanf("%d",&n);
    for(i=0;i<=n;i++)
    {
        p=(List)malloc(sizeof(struct Node));
        p->Next=NULL;
        if(i==0)
        {
            head=tail=p;
        }
        else
        {
            scanf("%d",&p->Data);
            tail->Next=p;
            tail=p;
        }
    }
    return head;
}

void Print( List L )
{
    List t=L;
    if(t->Next==NULL)
    {
        printf("NULL\n");
    }
    else
    {
        while(t->Next)
        {
            printf("%d ",t->Next->Data);
            t=t->Next;
        }
        printf("\n");
    }
}

// /* 你的代码将被嵌在这里 */
List Merge( List L1, List L2 )
{
    List p1,p2,L,pL;
    pL=(List)malloc(sizeof(struct Node));
    L = pL;
    p1 = L1->Next;
    p2 = L2->Next;
    /* -------------- For Test --------------------- */
    // pL = L2;
    // pL->Next = L2;
    // pL = pL->Next;
    // pL->Next = L1;
    /* -------------- For Test --------------------- */
    while(p1&&p2)
    {
        if(p1->Data>p2->Data)
        {
            pL->Next = p2;
            p2 = p2->Next;
        }
        else
        {
            pL->Next = p1;
            p1 = p1->Next;
        }
        pL = pL->Next;
    }
    pL->Next = p1 ? p1 : p2;
    L1->Next = NULL;
    L2->Next = NULL;
    return L;
}
